package day0307

func romanToInt(s string) (res int) {
	hmp := map[byte]int{
		'I': 1,
		'V': 5,
		'X': 10,
		'L': 50,
		'C': 100,
		'D': 500,
		'M': 1000,
	}
	n := len(s)
	tmp := 0
	for i := n - 1; i >= 0; i-- {
		t := hmp[s[i]]
		if t < tmp {
			res -= t
		} else {
			res += t
		}
		tmp = t
	}
	return
}
